package jp.co.hcs.attendancemanagement.inputdailyattendance.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.co.hcs.attendancemanagement.action.AMAction;
import jp.co.hcs.attendancemanagement.inputdailyattendance.logic.GetWorkingTimeInfoLogic;
import jp.co.hcs.attendancemanagement.inputdailyattendance.logic.dto.TimeSettingInitDTO;
import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class GetWorkingTimeInfoAction extends AMAction {

  public ActionForward executeImpl(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    String workingTimeId = (String) request.getParameter("id");
    if (workingTimeId == null) {
      return null;
    }

    response.setContentType("text/json");

    GetWorkingTimeInfoLogic logic = new GetWorkingTimeInfoLogic();
    TimeSettingInitDTO workingTime = logic.getWorkingTimeById(workingTimeId);

    JSONObject jsonObj = JSONObject.fromObject(workingTime);

    PrintWriter pw = response.getWriter();
    pw.write(jsonObj.toString());
    pw.flush();
    pw.close();

    return null;
  }

}
